/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.activity.controller.c;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykht.proj.activity.entity.CnActivity;
import com.ykht.proj.activity.service.CnActivityService;
import com.ykht.proj.activity.vo.ActivityVo;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.comsrv.api.feign.RemoteSubsribeMsgService;
import com.ykht.proj.comsrv.constant.ComConstant;
import com.ykht.proj.comsrv.vo.SubscribeMsg;
import com.ykht.proj.comsrv.vo.SubscribeMsgActivityNotice;
import com.ykht.proj.coupon.api.feign.RemoteShopService;
import com.ykht.proj.coupon.entity.CnShop;
import com.ykht.proj.coupon.vo.CnShopSimpleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;


/**
 * 活动表
 *
 * @author csg
 * @date 2020-12-23 11:13:32
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("c/act" )
@Api(value = "cnactivity", tags = "c端活动相关")
public class ActivityController {

    private final  CnActivityService cnActivityService;
    private final RemoteSubsribeMsgService remoteSubsribeMsgService;




	@ApiOperation(value = "活动提醒")
	@GetMapping("/sendActivityNotie" )
	public R sendActivityNotie(SubscribeMsgActivityNotice msg) {
		msg.setType(ComConstant.SUBSCRIBE_MSG_ACTIVITY_NOTICE);
		remoteSubsribeMsgService.send(msg);
		return R.ok();
	}
	@ApiOperation(value = "首页分类标签", notes = "首页分类标签")
	@GetMapping("/list4Home" )
	public R<List<CnActivity>> list() {
		List<CnActivity> list = cnActivityService.list(Wrappers.lambdaQuery(CnActivity.class)
				.eq(CnActivity::getDisplay,0)
				.eq(CnActivity::getExpireStatus,0)
				.le(CnActivity::getStartTime, LocalDateTime.now())
				.orderByAsc(CnActivity::getSort)
				.last("limit 7"));
		return R.ok(list);
	}



	@ApiOperation(value = "吃哪网活动节", notes = "吃哪网活动节")
	@GetMapping("/page" )
	public R<Page<CnActivity>> getCnActivityPage(Page page) {
		page = cnActivityService.page(page, Wrappers.lambdaQuery(CnActivity.class)
				.eq(CnActivity::getDisplay,0)
				.le(CnActivity::getStartTime, LocalDateTime.now())
				.orderByAsc(CnActivity::getExpireStatus).orderByAsc(CnActivity::getSort));
		return R.ok(page);
	}

    /**
     * 通过id查询活动表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询活动详情", notes = "通过id查询活动详情")
    @GetMapping("/{id}" )
    public R<ActivityVo> getById(Page page,@PathVariable("id" ) Long id,String longitude,String latitude) {

		R<ActivityVo> r = cnActivityService.getActivityById(page, id,longitude,latitude);
		return r;
    }


}
